<template>
    <template v-if="user">
        <van-cell title="用户名" is-link :value="user.username" @click="toEdit('username','用户名',user.username)"/>
        <van-cell title="账户" is-link  :value="user.userAccount" @click="toEdit('userAccount','账户',user.userAccount)"/>
        <van-cell title="头像" is-link @click="toEdit('avatar','头像',user.avatar)">
            <img style="height: 48px" :src="user.avatar?user.avatar:defaultPicture">
        </van-cell>
        <van-cell title="性别" is-link :value="user.gender = user.gender == 0 ? '男' : '女'" @click="toEdit('gender','性别',user.gender)"/>
        <van-cell title="电话" is-link  :value="user.phone" @click="toEdit('phone','电话',user.phone)"/>
        <van-cell title="邮箱" is-link  :value="user.email" @click="toEdit('email','邮箱',user.email)"/>
        <van-cell title="创建时间" is-link  :value="user.createTime" />
    </template>

</template>

<script setup lang="ts">
    import {useRouter} from "vue-router"
    import {onMounted,ref} from 'vue'
    import myAxois from "../plugin/MyAxios";
    import {showFailToast, showSuccessToast} from "vant";
    import {getCurrentUser} from "../service/user";
    import {defaultPicture} from '../common/userCommand';


    const user = ref()
    onMounted(async () => {
        //获取当前登录的用户信息
        const res = await getCurrentUser();
        if(res.data.code === 0 && res.data.data){
            showSuccessToast("获取当前用户成功！")
            user.value = res.data.data;
        }else{
            showFailToast("获取当前用户失败!")
        }
    })

    const router = useRouter();
    //这里参数editKey、editName、currentValue对应上面三个参数。
    const toEdit = (editKey:string,editName:string,currentValue:string) =>{
        router.push({
            path:'/user/edit',//跳转的页面
            query:{//将参数传递到跳转的页面
                editKey,
                editName,
                currentValue
            }
        })
    }
</script>

<style scoped>

</style>